package cn.yzy.ui;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;

import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JPanel;

import cn.yzy.main.PrConstant;

public class ConfigPanel extends JPanel {
	private ConfigPanel_controller controller;
	private ConfigPanel_bean bean;
	private JButton database_BT;
	private List<Action> listeners=new ArrayList<Action>();
	private Action databaseAction;
	

	public ConfigPanel() {
		bean = new ConfigPanel_bean();
		controller = new ConfigPanel_controller(this);
		// setBorder(BorderFactory.createEtchedBorder());
		createComponent();
		layoutComponent();
		addListener();
		setName("configPanel");
	}

	private void addListener() {
		database_BT.addActionListener(controller);
	}

	/**
	 * done
	 */
	private void createComponent() {
		database_BT = getDatabaseButton();
	}

	private JButton getDatabaseButton() {
		if(database_BT==null) {
			database_BT=new JButton();
			database_BT.setAction(getDatabaseAction());
		}
		return database_BT;
	}

	private Action getDatabaseAction() {
		if(databaseAction==null) {
			databaseAction=new DatabaseAction(controller);
		}
		return databaseAction;
	}

	/**
	 * done
	 */
	private void layoutComponent() {
		setLayout(new FlowLayout(FlowLayout.LEFT));
		add(database_BT);
	}

	public ConfigPanel_controller getController() {
		return controller;
	}

	public ConfigPanel_bean getbean() {
		return bean;
	}
	
	public void fireConfigPanelEvent(String command) {
		for (Action listener : listeners) {
			listener.actionPerformed(new ActionEvent(this, 0, command));
		}
	}
	
	public void addConfigPanelListener(Action listener) {
		listeners.add(listener);
	}

}
